<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="建筑垃圾联运订单号" prop="tranOrderCode">
        <el-input
          v-model="queryParams.tranOrderCode"
          placeholder="请输入建筑垃圾联运订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆carId" prop="carId">
        <el-input
          v-model="queryParams.carId"
          placeholder="请输入车辆carId"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾驶员ID" prop="driverId">
        <el-input
          v-model="queryParams.driverId"
          placeholder="请输入驾驶员ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌号码" prop="plate">
        <el-input
          v-model="queryParams.plate"
          placeholder="请输入车牌号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车牌颜色" prop="plateColor">
        <el-input
          v-model="queryParams.plateColor"
          placeholder="请输入车牌颜色"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间yyyy-MM-dd HH:mm:ss" prop="startTime">
        <el-input
          v-model="queryParams.startTime"
          placeholder="请输入开始时间yyyy-MM-dd HH:mm:ss"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="结束时间" prop="endTime">
        <el-input
          v-model="queryParams.endTime"
          placeholder="请输入结束时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间跟结束时间的间隔(s)" prop="timeConsume">
        <el-input
          v-model="queryParams.timeConsume"
          placeholder="请输入开始时间跟结束时间的间隔(s)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工地(外键)" prop="constructionSiteId">
        <el-input
          v-model="queryParams.constructionSiteId"
          placeholder="请输入工地(外键)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="土场(外键)" prop="soilFieldId">
        <el-input
          v-model="queryParams.soilFieldId"
          placeholder="请输入土场(外键)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工地名称" prop="constructionSiteName">
        <el-input
          v-model="queryParams.constructionSiteName"
          placeholder="请输入工地名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="土场名称" prop="soilFieldName">
        <el-input
          v-model="queryParams.soilFieldName"
          placeholder="请输入土场名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="距离" prop="distance">
        <el-input
          v-model="queryParams.distance"
          placeholder="请输入距离"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="atime">
        <el-input
          v-model="queryParams.atime"
          placeholder="请输入创建时间"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="车辆体积m³" prop="cargoVolume">
        <el-input
          v-model="queryParams.cargoVolume"
          placeholder="请输入车辆体积m³"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业(外键)" prop="transportationCompanyId">
        <el-input
          v-model="queryParams.transportationCompanyId"
          placeholder="请输入企业(外键)"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="enterpriseName">
        <el-input
          v-model="queryParams.enterpriseName"
          placeholder="请输入企业名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="土方价格" prop="soilVolumePrice">
        <el-input
          v-model="queryParams.soilVolumePrice"
          placeholder="请输入土方价格"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工地企业ID" prop="constructionSiteCompanyId">
        <el-input
          v-model="queryParams.constructionSiteCompanyId"
          placeholder="请输入工地企业ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="处置场所企业ID" prop="soilSiteCompanyId">
        <el-input
          v-model="queryParams.soilSiteCompanyId"
          placeholder="请输入处置场所企业ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['modules:order:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['modules:order:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['modules:order:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['modules:order:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键" align="center" prop="id" />
      <el-table-column label="建筑垃圾联运订单号" align="center" prop="tranOrderCode" />
      <el-table-column label="车辆carId" align="center" prop="carId" />
      <el-table-column label="驾驶员ID" align="center" prop="driverId" />
      <el-table-column label="车牌号码" align="center" prop="plate" />
      <el-table-column label="建筑垃圾类型" align="center" prop="wasteType" />
      <el-table-column label="车辆类型-必填:1.五小工程车 2.商砼车 3.渣土车 4.泥浆车 5.泵车 6.挖机" align="center" prop="vehicleType" />
      <el-table-column label="车牌颜色" align="center" prop="plateColor" />
      <el-table-column label="开始时间yyyy-MM-dd HH:mm:ss" align="center" prop="startTime" />
      <el-table-column label="结束时间" align="center" prop="endTime" />
      <el-table-column label="开始时间跟结束时间的间隔(s)" align="center" prop="timeConsume" />
      <el-table-column label="工地(外键)" align="center" prop="constructionSiteId" />
      <el-table-column label="土场(外键)" align="center" prop="soilFieldId" />
      <el-table-column label="工地名称" align="center" prop="constructionSiteName" />
      <el-table-column label="土场名称" align="center" prop="soilFieldName" />
      <el-table-column label="距离" align="center" prop="distance" />
      <el-table-column label="创建时间" align="center" prop="atime" />
      <el-table-column label="车辆体积m³" align="center" prop="cargoVolume" />
      <el-table-column label="企业(外键)" align="center" prop="transportationCompanyId" />
      <el-table-column label="企业名称" align="center" prop="enterpriseName" />
      <el-table-column label="土方价格" align="center" prop="soilVolumePrice" />
      <el-table-column label="工地企业ID" align="center" prop="constructionSiteCompanyId" />
      <el-table-column label="处置场所企业ID" align="center" prop="soilSiteCompanyId" />
      <el-table-column label="数据状态" align="center" prop="status" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['modules:order:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['modules:order:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改建筑垃圾联运订单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="建筑垃圾联运订单号" prop="tranOrderCode">
          <el-input v-model="form.tranOrderCode" placeholder="请输入建筑垃圾联运订单号" />
        </el-form-item>
        <el-form-item label="车辆carId" prop="carId">
          <el-input v-model="form.carId" placeholder="请输入车辆carId" />
        </el-form-item>
        <el-form-item label="驾驶员ID" prop="driverId">
          <el-input v-model="form.driverId" placeholder="请输入驾驶员ID" />
        </el-form-item>
        <el-form-item label="车牌号码" prop="plate">
          <el-input v-model="form.plate" placeholder="请输入车牌号码" />
        </el-form-item>
        <el-form-item label="车牌颜色" prop="plateColor">
          <el-input v-model="form.plateColor" placeholder="请输入车牌颜色" />
        </el-form-item>
        <el-form-item label="开始时间yyyy-MM-dd HH:mm:ss" prop="startTime">
          <el-input v-model="form.startTime" placeholder="请输入开始时间yyyy-MM-dd HH:mm:ss" />
        </el-form-item>
        <el-form-item label="结束时间" prop="endTime">
          <el-input v-model="form.endTime" placeholder="请输入结束时间" />
        </el-form-item>
        <el-form-item label="开始时间跟结束时间的间隔(s)" prop="timeConsume">
          <el-input v-model="form.timeConsume" placeholder="请输入开始时间跟结束时间的间隔(s)" />
        </el-form-item>
        <el-form-item label="工地(外键)" prop="constructionSiteId">
          <el-input v-model="form.constructionSiteId" placeholder="请输入工地(外键)" />
        </el-form-item>
        <el-form-item label="土场(外键)" prop="soilFieldId">
          <el-input v-model="form.soilFieldId" placeholder="请输入土场(外键)" />
        </el-form-item>
        <el-form-item label="工地名称" prop="constructionSiteName">
          <el-input v-model="form.constructionSiteName" placeholder="请输入工地名称" />
        </el-form-item>
        <el-form-item label="土场名称" prop="soilFieldName">
          <el-input v-model="form.soilFieldName" placeholder="请输入土场名称" />
        </el-form-item>
        <el-form-item label="距离" prop="distance">
          <el-input v-model="form.distance" placeholder="请输入距离" />
        </el-form-item>
        <el-form-item label="创建时间" prop="atime">
          <el-input v-model="form.atime" placeholder="请输入创建时间" />
        </el-form-item>
        <el-form-item label="车辆体积m³" prop="cargoVolume">
          <el-input v-model="form.cargoVolume" placeholder="请输入车辆体积m³" />
        </el-form-item>
        <el-form-item label="企业(外键)" prop="transportationCompanyId">
          <el-input v-model="form.transportationCompanyId" placeholder="请输入企业(外键)" />
        </el-form-item>
        <el-form-item label="企业名称" prop="enterpriseName">
          <el-input v-model="form.enterpriseName" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="土方价格" prop="soilVolumePrice">
          <el-input v-model="form.soilVolumePrice" placeholder="请输入土方价格" />
        </el-form-item>
        <el-form-item label="工地企业ID" prop="constructionSiteCompanyId">
          <el-input v-model="form.constructionSiteCompanyId" placeholder="请输入工地企业ID" />
        </el-form-item>
        <el-form-item label="处置场所企业ID" prop="soilSiteCompanyId">
          <el-input v-model="form.soilSiteCompanyId" placeholder="请输入处置场所企业ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/modules/order";

export default {
  name: "Order",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 建筑垃圾联运订单信息表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        tranOrderCode: null,
        carId: null,
        driverId: null,
        plate: null,
        wasteType: null,
        vehicleType: null,
        plateColor: null,
        startTime: null,
        endTime: null,
        timeConsume: null,
        constructionSiteId: null,
        soilFieldId: null,
        constructionSiteName: null,
        soilFieldName: null,
        distance: null,
        atime: null,
        cargoVolume: null,
        transportationCompanyId: null,
        enterpriseName: null,
        soilVolumePrice: null,
        constructionSiteCompanyId: null,
        soilSiteCompanyId: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询建筑垃圾联运订单信息列表 */
    getList() {
      this.loading = true;
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        tranOrderCode: null,
        carId: null,
        driverId: null,
        plate: null,
        wasteType: null,
        vehicleType: null,
        plateColor: null,
        startTime: null,
        endTime: null,
        timeConsume: null,
        constructionSiteId: null,
        soilFieldId: null,
        constructionSiteName: null,
        soilFieldName: null,
        distance: null,
        atime: null,
        cargoVolume: null,
        transportationCompanyId: null,
        enterpriseName: null,
        soilVolumePrice: null,
        constructionSiteCompanyId: null,
        soilSiteCompanyId: null,
        status: null,
        createTime: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加建筑垃圾联运订单信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改建筑垃圾联运订单信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除建筑垃圾联运订单信息编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('modules/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
